<!-- 产品展示页 -->
<template>
	<view class="p-display">
		<!-- 搜索栏 -->
		<view class="p-search-box">
			<view class="p-search">
				<u-icon name="e61e" size="48" color="#999999" custom-prefix="iconfont" />
				<input class="p-search-ipt" type="text" v-model='searchIpt' placeholder="请输入搜索内容" />
			</view>
			<view class="p-add" @click="onEdit(false)">
				<image src="../../static/add.jpg" class="p-add-image" />
				<view class="p-add-title">新增</view>
			</view>
		</view>
		<!-- tabs选择栏 -->
		<u-tabs :list="tabList" height='66' :current="current" @change="onChangeTab"></u-tabs>

		<template v-if="dataList[0]">
			<!-- 产品展示 -->
			<view class="product" >
				<view class="product-item" v-for="(item,index) in dataList" :key='index'>
					<view class="pi-top">
						<view class="product-img">
							<image :src="item.logo?item.logo:require('../../static/nopic2.png')" class="product-img" />
							<view class="product-img-title">
								{{item.type==2?'秒杀':'普通'}}
							</view>
						</view>
						<view class="product-item-center">
							<view class="product-item-center-name u-line-2">{{item.name}} </view>
							<view class="product-stock">
								<view class="product-stock-price">￥{{item.price?item.price:0}}</view>
								<view class="product-stock-number">库存：{{item.stock_num?item.stock_num:0}}</view>
							</view>
						</view>
					</view>
					<view class="product-item-right">
						<view class="btn-box">
							<view class="product-fun" @click="onEdit(item.pk_id)">
								<image class="fun-icon" src="../../static/ic_2.png" mode=""></image>
								<text>编辑</text>
							</view>
							<view class="product-fun" @click="onInventory(item.pk_id)">
								<image class="fun-icon" src="../../static/ic_3.png" mode=""></image>
								<text>库存</text>
								</view>
							<view class="product-fun" style="margin-right: 0;" @click="onDel(item.pk_id)">
								<image class="fun-icon" style="width: 32rpx;" src="../../static/ic_1.png" mode=""></image>
								<text>删除</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</template>

		<template v-else>
			<view class="empty">
				<u-empty text="暂无数据" mode="list"/>
			</view>
		</template>


	</view>
</template>

<script>
	import {
		pagingMixin
	} from '@/mixins/sysPaging.js'
	import {uniModal,uniToast} from '@/utils/uniPromise.js'
	export default {
		mixins: [pagingMixin],
		data() {
			return {
				dpwnUpList: [{
						name: '上架',
						value: 1
					},
					{
						name: '下架',
						value: 0
					}
				],
				searchIpt: '',
				dpwnUpId: 0,
				tabList: [],
				InterfaceParams: {
					one_level: '',
					business_id: '',
					name: ''
				},
				current: 0,
				dataList: [],
			}
		},
		watch: {
			searchIpt(news) {
				this.InterfaceParams.name = news
				this._init_data('AdminProductList', {
					...this.InParams,
					supplier_id:this.vuex_adminuser.supplier_id
				})


			}
		},
		onShow() {
			this.initPage()
		},
		onReachBottom() {
			this._load_data()
		},
		computed: {
			InParams() {
				let params = {
					...this.InterfaceParams
				}

				params = this.seekObject(params)
				return params
			}
		},
		methods: {
			// 初始化页面
			initPage() {
				this.InterfaceParams.business_id = this.vuex_business.pk_id
				let params = {
					type: 1,
					parents: 0,
					fk_business_id: this.vuex_business.pk_id
				}
				this.$GetQueryDataList('m_common_classify', 1, 9999, {
					...params
				}, {
					sort: 'sort asc,pk_id desc'
				}).then(res => {
					let arr =[{
					name: '全部',
					value: -1
				}]
					res.data.forEach(el => {
						arr.push({
							name: el.name,
							value: Number(el.pk_id)
						})
					})
					this.tabList = arr
				})

				this._init_data('AdminProductList', {
					...this.InParams,
					supplier_id:this.vuex_adminuser.supplier_id
				})

			},

			// 寻找对象里面是否有空值
			seekObject(el) {
				let data = JSON.parse(JSON.stringify(el))
				for (let i in data) {
					if (!data[i]) {
						delete data[i]
					}
				}
				return data
			},

			// 点击tabs切换
			onChangeTab(index) {
				this.current = index;
				this.InterfaceParams.one_level = this.tabList[index].value //获取产品类型ID
				this._init_data('AdminProductList', {
					...this.InParams,
					supplier_id:this.vuex_adminuser.supplier_id
				})
			},

			// 编辑产品
			onEdit(pk_id) {
				this.$to(`/package/supplierSide/product/p-display/edit/index?id=${pk_id}`)
			},
			onDel(id){
				uniModal({
					content:'确定删除该条商品'
				}).then(res=>{
					if(res== 'success'){
						this.$DeleteManagerData(1,id).then((res)=>{
							uniToast(res.msg)
							this.initPage()
						})
					}
				})
				
			},
			//管理库存
			onInventory(pk_id) {
				this.$to(`/package/supplierSide/product/p-stock/index?id=${pk_id}`)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.p-search-box {
		display: flex;
		width: 100%;
		height: 108rpx;
		background: #FFFFFF;
		padding: 20rpx 30rpx;
		border-bottom: 1px solid #f5f5f5;

		// 搜索左边布局
		.p-search {
			display: flex;
			padding: 0 20rpx;
			box-sizing: border-box;
			width: 570rpx;
			height: 68rpx;
			background: #EDEDED;
			border-radius: 8rpx;
			margin-right: 20rpx;

			.p-search-ipt {
				width: 100%;
				height: 100%;
			}
		}

		// 搜索右边布局
		.p-add {
			flex: 1;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.p-add-title {
				font-size: 26rpx;
				font-weight: 500;
				color: #222222;
			}

			.p-add-image {
				width: 33rpx;
				height: 34rpx;
				margin-right: 12rpx;
			}
		}

	}
	.btn-box{
		width: 70%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 0 auto;
	}
	.pi-top{
		display: flex;
		padding-bottom: 20rpx;
		border-bottom: 1px solid #f1f1f1;
		margin-bottom: 20rpx;
	}
	// 产品展示
	.product {
		width: 100%;
		min-height: 100vh;
		background-color: #f5f5f5;
		padding: 20rpx 30rpx;
		box-sizing: border-box;
		border-radius: 10rpx;

		.product-img {
			position: relative;
			width: 178rpx;
			height: 178rpx;
			margin-right: 21rpx;
			border-radius: 10rpx;

			.product-img-title {
				position: absolute;
				left: 0;
				top: 0;
				width: 59rpx;
				height: 34rpx;
				text-align: center;
				line-height: 34rpx;
				color: #ffffff;
				background: #C532EF;
				border-radius: 8rpx 0 8rpx 0;
				background-color: #C532EF;
				font-size: 24rpx;
			}
		}

		.product-item {
			display: flex;
			background-color: #fff;
			padding: 22rpx;
			box-sizing: border-box;
			flex-direction: column;
			border-radius: 8rpx;
			margin-bottom: 20rpx;

			.product-item-center {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				width: 76%;
				font-size: 28rpx;
				font-weight: bold;
				color: #002222;

				.product-item-center-name {
					font-size: 28rpx;
					font-weight: bold;
					color: #002222;
				}

				.product-stock-number {
					font-size: 26rpx;
					font-weight: 500;
					color: #999999;
				}

				.product-stock-price {
					margin-right: 20rpx;
					font-size: 30rpx;
					font-weight: 500;
					color: #FF0E0E;
				}
			}
		}
		.product-stock{
			display: flex;
			align-items: center;
		}
		.product-item-right {
			display: flex;
			// flex-direction: column;
			align-items: center;
			justify-content: space-between;

			.pro-down-up {
				display: flex;
				width: 150rpx;
				height: 46rpx;
				border-radius: 4rpx;
				box-sizing: border-box;
				border: 1px solid #3297EF;

				.pro-down-up-title {
					flex: 1;
					color: #3297EF;
					font-size: 26rpx;
					text-align: center;
				}

				.pro-down-up-active {
					color: #fff;
					background-color: #3297EF;
				}
			}

			.product-fun {
				// width: 120rpx;
				text-align: center;
				// line-height: 46rpx;
				margin-right: 20rpx;
				height: 46rpx;
				background: #FFFFFF;
				display: flex;
				align-items: center;
				font-size: 24rpx;
				font-weight: 500;
				color: #999;
				.fun-icon{
					width: 40rpx;
					height: 40rpx;
					margin-right: 10rpx;
				}
			}
		}
	}
	
	
	.empty {
		position: fixed;
		top: 50%;
		transform: translateY(-50%);
		width: 100%;
		margin: 0 auto;
	}
	
	
</style>
